
#pragma once

namespace serial {

class Device {
public:
    Device(const char * node = 0);
    virtual ~Device();

    typedef enum {
        NO_FLOWCTRL = 0,
        HARDWARE_FLOWCTRL,
        SOFTWARE_FLOWCTRL,
    } FLOWCONTROL;
    typedef enum {
        NONE,
        EVEN,
        ODD,
    } PARITY;

    bool init(const char * node = 0, int bitrate = 115200, int databit = 8, PARITY parity = NONE, int stopbit = 1, FLOWCONTROL flowcontrol = NO_FLOWCTRL);
    int read();
    virtual void onRead(const char * buf, int len) = 0;

    int fd() { return mFd; }
    void reset();

private:
    int mFd;
    int findBitrate(int bitrate);
    char * mNode;
};
} //namespace serial

